package top.gbyun.engine.actor;

import akka.actor.Props;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import top.gbyun.core.ActorSystemContext;
import top.gbyun.core.entity.FlowInfo;
import top.gbyun.core.entity.NodeInfo;
import top.gbyun.core.msg.NodeMsg;
import top.gbyun.engine.processor.NodeActorMsgProcessor;

/**
 * @author gengbin
 * @date 2024-12-23-16:59
 */
public class NodeActor extends ComponentActor<NodeActorMsgProcessor> {
    private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);

    public NodeActor(ActorSystemContext systemContext, NodeInfo nodeInfo, FlowInfo flowInfo) {
        super(flowInfo.getId(),systemContext);
        setProcessor(new NodeActorMsgProcessor(systemContext,flowInfo,nodeInfo, getContext()));
    }

    public static Props props(ActorSystemContext systemContext, NodeInfo  nodeInfo,FlowInfo flowInfo) {
        return Props.create(NodeActor.class, () -> new NodeActor(systemContext,nodeInfo,flowInfo));
    }


    @Override
    public Receive createReceive() {
        return receiveBuilder().match(NodeMsg.class, msg->{
            processor.onFlowToNodeMsg(msg);
        }).build();
    }
}
